home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-12 | 16.3 KB | 528 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: IntlTest.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "IntlTest.hpp"
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- // for gDefaultFontMenu and gJFontMenu
- #ifndef EDITVIEWS_H
- #include "EditViews.h"
- #endif
-
- #ifndef DIALOGS_H
- #include "Dialogs.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWFONTLI_H
- #include "FWFontLi.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- //========================================================================================
- // Constants and Globals
- //========================================================================================
-
- FW_Locale gJapaneseLocale = { smJapanese, langJapanese };
-
- short gAppleMenuID;
-
- // Function prototypes to satisfy compiler
-
- void AddFontsToMenu(Environment* ev, FW_CPullDownMenu* menu, FW_Boolean singleByte);
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfIntlTest
- #endif
-
- //========================================================================================
- // CIntlTestPart class
- //========================================================================================
-
- FW_DEFINE_AUTO(CIntlTestPart)
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart constructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestPart::CIntlTestPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fPartContent(NULL),
- fMainPresentation(NULL),
- fOpTestPresentation(NULL),
- fReaderTestPresentation(NULL),
- fNumberTestPresentation(NULL),
- fTestFrame(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart destructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestPart::~CIntlTestPart()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CIntlTestPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)
- {
- FW_CPart::Initialize(ev, storageUnit, fromStorage);
-
- // ----- Register our Presentation
- CIntlTestSelection* selection = FW_NEW(CIntlTestSelection, (ev, this));
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, selection);
- fTestSelection = selection;
- fOpTestPresentation = RegisterPresentation(ev, kOpTestPresentation, false, kOpTestDialog, kOpTestDialog, NULL);
- fReaderTestPresentation = RegisterPresentation(ev, kReaderTestPresentation, false, kReaderTestDialog, kReaderTestDialog, NULL);
- fNumberTestPresentation = RegisterPresentation(ev, kNumberTestPresentation, false, kNumberTestDialog, kNumberTestDialog, NULL);
-
- // ----- Register our other kinds -----
- RegisterKind(ev, kODMacIText, FW_kDataInterchangeStorage, FW_kImportExportEnabled);
- RegisterKind(ev, kTEXTOSType, kODPlatformDataType, FW_kAllStorage, FW_kImportExportEnabled);
- RegisterKind(ev, kTEXTOSType, kODPlatformFileType, FW_kDataInterchangeStorage, FW_kImportExportEnabled);
- FW_CKind* partKind = GetPartKind(ev);
- partKind->ChangeStorageKind(ev, FW_kPartStorage | FW_kLinkStorage | FW_kFileStorage);
-
- // ----- Initialize my menus -----
- InitializeMenus(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::InitializeMenus
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::InitializeMenus(Environment* ev)
- {
- FW_PSharedLibraryResourceFile resFile(ev);
- FW_CMenuBar* menuBar = GetMenuBar(ev);
-
- // We instantiate a submenu item from the stream so we must
- // prevent it from being deadstripped.
- FW_DO_NOT_DEAD_STRIP(FW_CSubMenuItem);
-
- // ----- Create the default Font menu -----
- FW_CString32 title; // read title from resource
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kFontMenuString, title);
- FW_CPullDownMenu* fontMenu = new FW_CPullDownMenu(ev, title);
- AddFontsToMenu(ev, fontMenu, true); // single-byte fonts
- gDefaultFontMenu = fontMenu;
-
- // ----- Create the Japanese Font menu -----
- fontMenu = new FW_CPullDownMenu(ev, title);
- AddFontsToMenu(ev, fontMenu, false); // double-byte fonts
- gJFontMenu = fontMenu;
-
- // ----- Set the Font menu to the default one -----
- menuBar->AdoptMenuLast(ev, gDefaultFontMenu);
- gFontMenu = gDefaultFontMenu;
- gFontCount = gFontMenu->CountItems(ev);
-
- // ----- Create the Size menu -----
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kSizeMenuString, title);
- fontMenu = new FW_CPullDownMenu(ev, title);
-
- // ----- Add the Size menu items -----
- FW_CString32 sizeString;
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kSize9, sizeString);
- fontMenu->AppendTextItem(ev, sizeString, cFontSize9);
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kSize10, sizeString);
- fontMenu->AppendTextItem(ev, sizeString, cFontSize10);
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kSize12, sizeString);
- fontMenu->AppendTextItem(ev, sizeString, cFontSize12);
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kSize14, sizeString);
- fontMenu->AppendTextItem(ev, sizeString, cFontSize14);
- FW_LoadStringByID(ev, resFile, kIntlTestPartStrings, FW_kMultiStringRes, kSize18, sizeString);
- fontMenu->AppendTextItem(ev, sizeString, cFontSize18);
- menuBar->AdoptMenuLast(ev, fontMenu);
- gSizeMenuID = fontMenu->GetMenuID(ev); // menuID not assigned until menu is added to menuBar
-
- // ----- Try adding an additional item to the Apple menu -----
- short appleMenuID;
- short aboutItemID;
- FW_CAcquiredODMenuBar aqODMenuBar = menuBar->AcquireODMenuBar(ev);
- aqODMenuBar->GetMenuAndItem(ev, kODCommandAbout, &appleMenuID, &aboutItemID);
- ODPlatformMenu platformMenu = aqODMenuBar->GetMenu(ev, appleMenuID);
- ::InsertMenuItem(platformMenu, "\pTesting", aboutItemID); // insert after About item
- gAppleMenuID = appleMenuID;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CIntlTestPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage) // Override
- {
- FW_UNUSED(fromStorage);
-
- if (presentation == fMainPresentation)
- {
- fTestFrame = FW_NEW(CIntlTestFrame, (ev, odFrame, presentation, this));
- return fTestFrame;
- }
-
- if (presentation == fOpTestPresentation)
- {
- return FW_NEW(COpTestDialogFrame, (ev, odFrame, presentation, this));
- }
-
- if (presentation == fReaderTestPresentation)
- {
- return FW_NEW(CReaderTestDialogFrame, (ev, odFrame, presentation, this));
- }
-
- if (presentation == fNumberTestPresentation)
- {
- return FW_NEW(CNumberTestDialogFrame, (ev, odFrame, presentation, this));
- }
-
- return NULL;
- }
-
- //------------------------------------------------------------------------------
- // CIntlTestPart::NewPartContent
- //------------------------------------------------------------------------------
-
- FW_CContent* CIntlTestPart::NewPartContent(Environment* ev)
- {
- fPartContent = FW_NEW(CIntlTestContent, (ev, this));
- return fPartContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::DoAbout
- //----------------------------------------------------------------------------------------
- FW_Handled CIntlTestPart::DoAbout(Environment* ev)
- {
- ::FW_About(ev, this, kAboutBox);
-
- return FW_kHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled CIntlTestPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
- {
- FW_Handled menuHandled = FW_kHandled;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- FW_CAcquiredODMenuBar aqODMenuBar = GetMenuBar(ev)->AcquireODMenuBar(ev);
- if (aqODMenuBar->IsCommandSynthetic(ev, id))
- {
- short menuID, itemID;
- aqODMenuBar->GetMenuAndItem(ev, id, &menuID, &itemID);
- if (menuID == gAppleMenuID && itemID == 2)
- {
- FW_Beep();
- return FW_kHandled;
- }
- }
-
- switch (id)
- {
- case cFirstCommand:
- OpenOperatorTestDialog(ev);
- break;
-
- case cThirdCommand:
- OpenReaderTestDialog(ev);
- break;
-
- case cFifthCommand:
- OpenNumberTestDialog(ev, id);
- break;
-
- default:
- menuHandled = FW_kNotHandled;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled CIntlTestPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot)
- {
- FW_UNUSED(isRoot);
-
- if (hasMenuFocus)
- {
- // Some tests require that an edit view be active
- FW_Boolean isActiveEditView = true;
- ODID id = fTestFrame->GetActiveEditViewId(ev);
- if (id == 0)
- isActiveEditView = false;
- else if (fTestFrame->FindEditView(ev, id) == NULL)
- isActiveEditView = false;
-
- // ----- Set up the IntlTest menu
- menuBar->EnableCommand(ev, cFirstCommand, isActiveEditView);
- menuBar->EnableCommand(ev, cThirdCommand, isActiveEditView);
- menuBar->EnableCommand(ev, cFifthCommand, true);
- menuBar->EnableCommand(ev, cSeventhCommand, true);
- }
-
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- ODID CIntlTestPart::WhichEditViewIsActive(Environment* ev)
- {
- ODID target = fTestFrame->GetActiveEditViewId(ev);
- return target;
- }
-
- //----------------------------------------------------------------------------------------
- FW_CString MyLoadRStringByID(Environment* ev,
- FW_PResourceFile& file,
- FW_ResourceID resourceId,
- FW_ResourceType resourceType)
- {
- FW_ASSERT(resourceType == TESTSTRINGRES);
-
- // FW_RString resource header
- struct RStringHeader
- {
- FW_Locale fLocale;
- short fLengthWord;
- };
-
- FW_PResource resource(ev, file, resourceId, resourceType);
- FW_CAcquireResourceData data(ev, resource);
- RStringHeader* p = (RStringHeader*) data.GetData();
-
- FW_Locale* pLocale = (FW_Locale*) p;
- FW_CString string(((const FW_Char*)p)+sizeof(RStringHeader), p->fLengthWord, (const FW_Locale&)*pLocale);
- return string;
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::UpdateTextData(Environment* ev)
- {
- FW_CString s;
-
- if (fTestFrame) // fTestFrame is NULL when creating stationery
- {
- FW_CEditView* editView;
-
- editView = fTestFrame->FindEditView(ev, kEnglishEditView);
- s = editView->GetText(ev);
- fPartContent->SetTextData(ev, s, kEnglishEditView);
-
- editView = fTestFrame->FindEditView(ev, kJapaneseEditView);
- s = editView->GetText(ev);
- fPartContent->SetTextData(ev, s, kJapaneseEditView);
- }
- else // creating stationery - load default strings from resources
- {
- FW_PSharedLibraryResourceFile resFile(ev);
- s = MyLoadRStringByID(ev, resFile, kDefaultEngStringID, TESTSTRINGRES);
- fPartContent->SetTextData(ev, s, kEnglishEditView);
- s = MyLoadRStringByID(ev, resFile, kDefaultJStringID, TESTSTRINGRES);
- fPartContent->SetTextData(ev, s, kJapaneseEditView);
- }
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::UpdateViewsFromTextData(Environment* ev)
- {
- FW_CEditView* editView;
- FW_CString s;
-
- s = fPartContent->GetTextData(kEnglishEditView);
- editView = fTestFrame->FindEditView(ev, kEnglishEditView);
- editView->SetText(ev, s);
-
- s = fPartContent->GetTextData(kJapaneseEditView);
- editView = fTestFrame->FindEditView(ev, kJapaneseEditView);
- editView->SetText(ev, s);
- }
-
- //----------------------------------------------------------------------------------------
- void AddFontsToMenu(Environment* ev, FW_CPullDownMenu* menu, FW_Boolean singleByte)
- {
- short count = 0;
-
- // Get a list of all the fonts
- FW_CFontIterator fontIter; // creates a temporary FW_CFontList
- FW_CString fontName;
- FW_Locale locale;
- ODCommandID commandID = cFirstFontCommand;
- for (fontName = fontIter.First(); fontIter.IsNotComplete(); fontName = fontIter.Next())
- {
- fontName.GetLocale(locale);
- if (FW_LocaleIsSingleByte(locale) == singleByte)
- {
- // Add a menu item for this font
- menu->AppendTextItem(ev, fontName, commandID+count);
- count++;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- CMyEditView* CIntlTestPart::GetActiveEditView(Environment* ev)
- {
- FW_CEditView* editView = NULL;
- ODID id = fTestFrame->GetActiveEditViewId(ev);
- if (id)
- {
- editView = fTestFrame->FindEditView(ev, id);
- }
- if (editView == NULL) return NULL; // none of the edit views is active
- return (CMyEditView*)editView;
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::OpenOperatorTestDialog(Environment* ev)
- {
- // Find the active edit view
- CMyEditView* editView = GetActiveEditView(ev);
-
- FW_CPoint position(FW_kZeroPoint);
- FW_CPoint size(FW_IntToFixed(300), FW_IntToFixed(160));
- FW_WindowStyle style = FW_kStandardDialogPosition | FW_kHasCaption;
-
- COpTestDialogFrame* dialog = (COpTestDialogFrame*) FW_CDialogFrame::NewModalDialog(ev,
- this, // Your part
- fOpTestPresentation, // Used in NewFrame
- size, // Window size
- position, // Window position
- style, // Make dialog moveable
- FW_CString("operator[] Test")); // Title for moveable dialog
-
- if (dialog != NULL)
- {
- dialog->Initialize(ev, editView);
- dialog->GetWindow(ev)->Show(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::OpenNumberTestDialog(Environment* ev, ODCommandID id)
- {
- FW_CString title("Real Number Test");
- FW_CPoint position(FW_kZeroPoint);
- FW_CPoint size(FW_IntToFixed(300), FW_IntToFixed(160));
- FW_WindowStyle style = FW_kStandardDialogPosition | FW_kHasCaption;
-
- CNumberTestDialogFrame* dialog = (CNumberTestDialogFrame*) FW_CDialogFrame::NewModalDialog(ev,
- this, // Your part
- fNumberTestPresentation, // Used in NewFrame
- size, // Window size
- position, // Window position
- style, // Make dialog moveable
- title); // Title for moveable dialog
-
- if (dialog != NULL)
- {
- dialog->Initialize(ev, (id == cSixthCommand));
- dialog->GetWindow(ev)->Show(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::OpenReaderTestDialog(Environment* ev)
- {
- // Find the active edit view
- CMyEditView* editView = GetActiveEditView(ev);
-
- FW_CPoint position(FW_kZeroPoint);
- FW_CPoint size(FW_IntToFixed(300), FW_IntToFixed(200));
- FW_WindowStyle style = FW_kStandardDialogPosition | FW_kHasCaption;
-
- CReaderTestDialogFrame* dialog = (CReaderTestDialogFrame*) FW_CDialogFrame::NewModalDialog(ev,
- this, // Your part
- fReaderTestPresentation, // Used in NewFrame
- size, // Window size
- position, // Window position
- style, // Make dialog moveable
- FW_CString("TextReader Test")); // Title for moveable dialog
-
- if (dialog != NULL)
- {
- dialog->Initialize(ev, editView);
- dialog->GetWindow(ev)->Show(ev);
- }
- }
-